import numpy as np
from scipy.spatial.distance import cosine

# 构建用户-绩点的关系矩阵（示例数据）
user_grades = {
    'User1': {'G1': 4.5, 'G2': 3.0, 'G3': 2.5},
    'User2': {'G1': 2.0, 'G2': 4.0, 'G3': 3.5},
    'User3': {'G1': 3.5, 'G2': 2.5, 'G3': 4.0},
}

users = list(user_grades.keys())
grades = list(user_grades[users[0]].keys())

user_grade_matrix = np.zeros((len(users), len(grades)))
for i, user in enumerate(users):
    for j, grade in enumerate(grades):
        user_grade_matrix[i, j] = user_grades[user][grade]

# 构建绩点-绩点的关系矩阵（示例数据）
grade_sim_matrix = np.zeros((len(grades), len(grades)))
for i in range(len(grades)):
    for j in range(len(grades)):
        grade1 = user_grade_matrix[:, i]
        grade2 = user_grade_matrix[:, j]
        grade_sim_matrix[i, j] = 1 - cosine(grade1, grade2)

# 基于CF生成每个用户的推荐列表（示例代码）
def get_user_recommendations(user_id, top_n=3):
    user_index = users.index(user_id)
    user_similarities = grade_sim_matrix[user_index, :]
